<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2021/12/25
 * Time: 16:18
 */

namespace app\admin\controller;

use app\admin\model\FightDetail;
use app\common\CacheKey;
use think\Db;

class Fight extends AdminBase
{
    public function fightlist()
    {
        $data = FightDetail::getInstance()->getList();

        $this->assign("data", $data['data']);
        $this->assign("dinosaur", config('app.dinosaur'));
        $this->assign("monster", config('app.monster'));
        $this->assign("page", $data['page']);
        $this->assign("keywords", input('param.keywords', ''));
        $this->assign("range", input('param.range', ''));
        $this->assign("monster_type", input('param.monster_type'));
        $this->assign("dinosaur_type", input('param.dinosaur_type'));

        return $this->fetch();
    }

    /**
     * @Title: export
     * @Describe
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     * @author lijunwei
     * @Date 2022/1/6 14:32
     */
    public function export()
    {
        $lists = FightDetail::getInstance()->exportExcel();
        $result = [];
        foreach ($lists as $key => $list) {
            $result[$key] = [
                'id' => $list['id'],
                'add_time' => $list['add_time'],
                'user_address' => $list['user_address'],
                'monster_name' => $list['monster_name'] . '(' . $list['monster_level_id'] . ')',
                'dinosaur_name' => $list['dinosaur_name'] . '(' . $list['dinosaur_level_id'] . ')',
                'residue_num' => $list['residue_num'],
                'nft_id' => $list['nft_id'],
                'fight_gold' => $list['fight_gold'],
                'drop_gold' => $list['drop_gold'],
                'gold_efficiency' => $list['gold_efficiency'],
            ];
        }
        $header = [
            'A' => [
                'title' => '战斗ID',
                'value' => 'id',
            ],
            'B' => [
                'title' => '出战时间',
                'value' => 'add_time',
            ],
            'C' => [
                'title' => '用户地址',
                'value' => 'user_address',
            ],
            'D' => [
                'title' => '怪物名称(级别)',
                'value' => 'monster_name',
            ],
            'E' => [
                'title' => '出战恐龙名称(级别)',
                'value' => 'dinosaur_name',
            ],
            'F' => [
                'title' => '剩余战斗次数(战后)',
                'value' => 'residue_num',
            ],
            'G' => [
                'title' => '恐龙NFT ID',
                'value' => 'nft_id',
            ],
            'H' => [
                'title' => '出战INGold',
                'value' => 'fight_gold',
            ],
            'I' => [
                'title' => '掉落INGold',
                'value' => 'drop_gold',
            ],
            'J' => [
                'title' => '金币效率',
                'value' => 'gold_efficiency',
            ]
        ];
        $name = '战斗明细';

        outExcel($result, $header, $name);
    }
}